<?php

namespace App\Http\Resources\NewWebSite;

use Illuminate\Http\Resources\Json\ResourceCollection;

class CityCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
             'code'=>0,
             'data'=>$this->collection->map(function($item){
                        return [
                            'city_id'=>$item->id,
                            'name'=>$item->title,

                            'children'=>$item->children->map(function($children){
                                    return [
                                        'second_city_id'=>$children->id,
                                        'name'=>$children->title,
                                    ];
                            })
                        ];
             })
        ];
    }
}

